package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.Ucenter;
import com.qj.yantaishan.service.IUcenterService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 用户中心Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/Ucenter")
public class UcenterController extends BaseController
{
    private String prefix = "yantaishan/Ucenter";

    @Autowired
    private IUcenterService ucenterService;

    @RequiresPermissions("yantaishan:ucenter:view")
    @GetMapping()
    public String ucenter()
    {
        return prefix + "/ucenter";
    }

    /**
     * 查询用户中心列表
     */
    @RequiresPermissions("yantaishan:ucenter:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Ucenter ucenter)
    {
        startPage();
        List<Ucenter> list = ucenterService.selectUcenterList(ucenter);
        return getDataTable(list);
    }

    /**
     * 导出用户中心列表
     */
    @RequiresPermissions("yantaishan:ucenter:export")
    @Log(title = "用户中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Ucenter ucenter)
    {
        List<Ucenter> list = ucenterService.selectUcenterList(ucenter);
        ExcelUtil<Ucenter> util = new ExcelUtil<Ucenter>(Ucenter.class);
        return util.exportExcel(list, "用户中心数据");
    }

    /**
     * 新增用户中心
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户中心
     */
    @RequiresPermissions("yantaishan:ucenter:add")
    @Log(title = "用户中心", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Ucenter ucenter)
    {
        return toAjax(ucenterService.insertUcenter(ucenter));
    }

    /**
     * 修改用户中心
     */
    @RequiresPermissions("yantaishan:ucenter:edit")
    @GetMapping("/edit/{storeId}")
    public String edit(@PathVariable("storeId") Integer storeId, ModelMap mmap)
    {
        Ucenter ucenter = ucenterService.selectUcenterByStoreId(storeId);
        mmap.put("ucenter", ucenter);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户中心
     */
    @RequiresPermissions("yantaishan:ucenter:edit")
    @Log(title = "用户中心", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Ucenter ucenter)
    {
        return toAjax(ucenterService.updateUcenter(ucenter));
    }

    /**
     * 删除用户中心
     */
    @RequiresPermissions("yantaishan:ucenter:remove")
    @Log(title = "用户中心", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ucenterService.deleteUcenterByStoreIds(ids));
    }
}
